package com.wsj.dao.hibernate;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wsj.dao.IHomeSiteAdAutopalyDao;
import com.wsj.util.tool.StringUtils;
import com.wsj.web.vo.homeSite.HomeSiteAdAutopaly;

public class HomeSiteAdAutopalyDaoImpl extends HibernateDaoSupport implements
		IHomeSiteAdAutopalyDao {
	
	private JdbcTemplate jdbcTemplate;

	public void delete(Integer id) throws DataAccessException {
		String sql = "delete from homeSite_ad_autopaly where id = "+id;
		this.jdbcTemplate.execute(sql);
	}

	@SuppressWarnings("unchecked")
	public List<HomeSiteAdAutopaly> loadAllList() throws DataAccessException {
		List list = null; 
		list = this.getHibernateTemplate().loadAll(HomeSiteAdAutopaly.class);
		if(list != null && list.size()>0){
			return list;
		}
		return null;
	}

	public HomeSiteAdAutopaly loadById(Integer id) throws DataAccessException {
		Object obj = null;
		HomeSiteAdAutopaly hs = null;
		obj = this.getHibernateTemplate().get(HomeSiteAdAutopaly.class,id);
		if(obj != null){
			hs = (HomeSiteAdAutopaly)obj;
		}
		return hs;
	}

	public void saveOrUpdate(HomeSiteAdAutopaly hs) throws DataAccessException {
		this.getHibernateTemplate().saveOrUpdate(hs);
	}
	
	@SuppressWarnings("unchecked")
	public List<HomeSiteAdAutopaly> loadTop(Integer top) throws DataAccessException {
		List list = null;
		String sql = " from HomeSiteAdAutopaly order by id desc ";
		list = this.getSession().createQuery(sql).setMaxResults(top).list();
		if(StringUtils.isNotNull(list)){
			return list;
		}
		return null;
	}


	

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

		
}
